home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8548 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  46 lines

  1. Newsgroups: comp.lang.pascal.misc,comp.lang.c++,comp.lang.c,comp.lang.pascal.borland
  2. Path: undergrad.math.uwaterloo.ca!clgonsal
  3. From: clgonsal@undergrad.math.uwaterloo.ca (Carl Laurence Gonsalves)
  4. Subject: Re: Tough FACTORIAL math problem...
  5. Sender: news@undergrad.math.uwaterloo.ca (news spool owner)
  6. Message-ID: <DMvKp5.2wL@undergrad.math.uwaterloo.ca>
  7. Date: Fri, 16 Feb 1996 15:36:40 GMT
  8. References: <4fr8be$ass@news.iconn.net> <31224679.6193@born.com> <4g00u6$gkk@sun001.spd.dsccc.com>
  9. Nntp-Posting-Host: cayley.uwaterloo.ca
  10. Organization: University of Waterloo
  11.  
  12. In article <4g00u6$gkk@sun001.spd.dsccc.com>,
  13. Mike McCarty <jmccarty@spd.dsccc.com> wrote:
  14. >)Don't just strip the trailing zeros, remove all digits except the last non-ze
  15. >)digit (which is your output) and then multiply by the next number in your seq
  16. >)This keeps the numbers down to a managable level and gives the correct answer
  17. >)no more significant digit can affect the value of the LSD.
  18. >
  19. >Let's try your technique:
  20. >
  21. >    1! = 1 ~ 1
  22. >    2! = 2x1! ~ 2
  23. >    3! = 3x2! ~ 3x2 = 6
  24. >    4! = 4x3! ~ 4x6 = 24 ~ 4
  25. >    5! = 5x4! ~ 5x4 = 20 ~ 0
  26. >
  27. >You should at least think before engaging the fingers.
  28.  
  29. Perhaps you should try *reading* before engaging the fingers. You'll notice
  30. he said "remove all digits except the last NON-ZERO digit". So one gets:
  31.  
  32.     1! = 1 ~ 1
  33.     2! = 2x1! ~ 2
  34.     3! = 3x2! ~ 3x2 = 6
  35.     4! = 4x3! ~ 4x6 = 24 ~ 4
  36.     5! = 5x4! ~ 5x4 = 20 ~ 2
  37.     6! = 6x5! ~ 6x2 = 12 ~ 2
  38.  
  39. This technique does give the correct result.
  40.  
  41. -- 
  42.         Carl Laurence Gonsalves - clgonsal@undergrad.math.uwaterloo.ca
  43.                    Computer Science, University of Waterloo
  44.                http://www.undergrad.math.uwaterloo.ca/~clgonsal/
  45.                    http://www.csclub.uwaterloo.ca/~clgonsal/
  46.